/*
 * AmplScript.cpp
 *
 *  Created on: 27 Jun 2011
 *      Author: s0965328
 */

#include "AmplScript.h"
#include "Sml.h"

using namespace std;

const string AmplScript::NAME = "script";

AmplScript::AmplScript(string model,int index,int script_num):fscript_writer()
{
	this->index = index;
	stringstream ss;
	ss<<AmplScript::NAME<<"_"<<model<<"_"<<script_num<<".scr";
	this->name = ss.str();
	this->fscript_writer.open(this->name.c_str(),fstream::out);
	Sml::instance()->scriptNameList.push_back(this->name);
}

void AmplScript::copyFrom(AmplScript* from)
{
	LOG_PAR("copyFrom - from["+from->name+"] to ["+this->name+"]");
	from->fscript_writer.flush();
	ifstream reader(from->name.c_str(),ifstream::in);
	string line;
	do
	{
		getline(reader,line);
		this->fscript_writer<<line<<endl;
		LOG_PAR(line);
	}
	while(!reader.eof());
	LOG_PAR("End copying");
}

AmplScript::~AmplScript() {
}
